package com.sky.common;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

public class common {

    /**
     * 还原URL：移除:443端口和查询参数
     * @param originalUrl 原始URL
     * @return 还原后的URL
     */
    @Bean
    public static String restoreUrl(String originalUrl) {
        if (originalUrl == null || originalUrl.isEmpty()) {
            return originalUrl;
        }

        // 步骤1：移除?及后面的查询参数
        int queryIndex = originalUrl.indexOf("?");
        String urlWithoutQuery = queryIndex != -1 ? originalUrl.substring(0, queryIndex) : originalUrl;

        // 步骤2：移除:443端口号（HTTPS默认端口可省略）
        String urlWithoutPort = urlWithoutQuery.replace(":443", "");

        return urlWithoutPort;
    }
}
